﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Framework;
using TrueSync;
using GameProtocols;

public class FightGame : IGame
{
    ObjHandle<LogicEntity> myPlayer = ObjHandle<LogicEntity>.NULL;
    ObjHandle<LogicEntity> otherPlayer = ObjHandle<LogicEntity>.NULL;

    FP CountDown;

    public void Init(params object[] gameParam)
    {
        CountDown = 60;

        int myEntityID = GameManager.Instance.CreateEntity(405000018, 0);
        myPlayer = GameManager.Instance.GetEntity(myEntityID);
        myPlayer.handle.GetLogicComponent<LogicMoveComponent>().SetPosition(new TSVector2(-2, 0));
        int otherEntityID = GameManager.Instance.CreateEntity(405000018, 1);
        otherPlayer = GameManager.Instance.GetEntity(otherEntityID);
        otherPlayer.handle.GetLogicComponent<LogicMoveComponent>().SetPosition(new TSVector2(2, 0));
    }

    public void onDestroy()
    {
       
    }

    public void Update(PKG_FRAME frame)
    {
        
        CountDown -= LockstepEngine.FrameDeltaTime;
        if (hasGameFinished())
        {
            //请求结算
            return;
        }
    }

    bool hasGameFinished()
    {
        if (CountDown < FP.Zero)
            return true;
        else
            return false;
    }

    

    public ObjHandle<LogicEntity> GetRival(LogicEntity self)
    {
        if (myPlayer.IsValid && self == myPlayer.handle)
            return otherPlayer;
        if (otherPlayer.IsValid && self == otherPlayer.handle)
            return myPlayer;
        return ObjHandle<LogicEntity>.NULL;
    }
}
